#find_package(TIFF REQUIRED)
#find_package(Qt5 5.4 REQUIRED COMPONENTS Core Widgets Gui)
#find_package(CURL REQUIRED)

set(CMAKE_AUTOMOC ON)

set(viewer_SRCS
	"main.cc"
	"tracer.cc"
	"annot.tree.cc"
	"splash.cc"
	"session.cc"

	"cache.thread.cc"
	"load.thread.cc"
	"compute.thread.cc"
	"xfunc.widget.cc"
	"dialogs.cc"
	"listmodel.cc"
	"options.cc"
	"options.dlg.cc"
	"options.page.cc"
	"plugin.manager.cc"
	"command.cc"
	"misc.cc"
	"viewer.cc"
	"color.widget.cc"
	)

QT5_ADD_RESOURCES(viewer_QRC resources.qrc)

add_executable(viewer ${viewer_SRCS} ${viewer_QRC})
target_link_libraries(viewer ${CURL_LIBRARIES} ${TIFF_LIBRARIES} Qt5::Core Qt5::Widgets Qt5::Gui)
target_link_libraries(viewer fntshared)
target_include_directories(viewer SYSTEM PUBLIC ${TIFF_INCLUDE_DIR} ${CURL_INCLUDE_DIR})
target_include_directories(viewer PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../shared/public")
target_include_directories(viewer PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../shared")
if(MINGW)
	target_link_libraries(viewer ws2_32)
endif()
if(WITH_VP9)
	target_link_libraries(viewer ${VPX_LIBRARIES} ${WEBM_LIBRARIES})
endif()
if(WITH_HEVC)
	target_link_libraries(viewer ${HEVC_LIBRARIES})
endif()
set_target_properties(viewer PROPERTIES OUTPUT_NAME "${PACKAGE_NAME}-viewer")
install(TARGETS viewer RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

function(fnt_plugin name)
	add_library(${name} SHARED "plugins/${name}.cc")
	set_target_properties(${name} PROPERTIES PREFIX "${PACKAGE_NAME}-plugin-")
	target_include_directories(${name} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../shared/public")
	if(MINGW)
		install(TARGETS ${name} RUNTIME DESTINATION "${CMAKE_INSTALL_PLUGINDIR}")
	else(MINGW)
		install(TARGETS ${name} LIBRARY DESTINATION "${CMAKE_INSTALL_PLUGINDIR}")
	endif(MINGW)
	if(${ARGC} GREATER 1)
		target_link_libraries(${name} ${ARGN})
	endif()
endfunction(fnt_plugin)

fnt_plugin(conv.allen.annot Qt5::Widgets)
fnt_plugin(annot.soma Qt5::Widgets)
fnt_plugin(neuron.stats Qt5::Widgets)

if(MINGW)
	if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
		#add_subdirectory(mingw)
	endif()
elseif(APPLE)
	if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
		add_subdirectory(bundle)
	endif()
else(MINGW)
	if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
		add_subdirectory(linux)
	endif()
endif(MINGW)

add_subdirectory(manual)

